/**
* @todo：组织树初始化
* @date：2008-7-31 18:02
* @author：hyh
*/
function ajaxTreeInit(){
	loadTreeParentNode();
	initTree();//初始化树
}

//读取父节点(固定方法)
function loadTreeParentNode(){
	DWRUtil.useLoadingMessage("正在读取数据...");
	DWREngine.setAsync(false);//设置同步
	imageFolder = "../components/folder-tree-static/images/";
	//父节点
	var html = "<ul id=\"ajax_tree\" class=\"dhtmlgoodies_tree\">";
	ConfigAction.getAclorganizationById("0",function(data){
		//配置A，id 提供修改时不用重新读取数据库
		html += "<li><a href=\"javascript:void(0);\" id=\""+  data.id+ "\" onclick=\"getDetail('"+ data.id +"');return false;\">"+ data.deptname +"</a><ul><li parentId=\""+ data.id +"\" class=\"loading.gif\"><a href=\"javascript:void(0);\">Loading...</a></li></ul></li>";
	});
	html += "</ul>";
	$("org_tree").innerHTML = html;
	DWREngine.setAsync(true);//设置异步
}

//读取子节点(固定方法)
function loadTreeChildNodes(ulId,parentId){
	DWRUtil.useLoadingMessage("正在读取数据...");
	var html = "";
	ConfigAction.listAclorganizationByParentId(parentId,function(data){
		if(data != null && data.length >0){
			for(var i = 0;i< data.length;i++){
				html += "<li><a href=\"javascript:void(0);\" id=\""+  data[i].id+ "\" onclick=\"getDetail('"+ data[i].id +"');return false;\">"+ data[i].deptname+ "</a><ul><li parentId=\""+ data[i].id +"\" class=\"loading.gif\"><a href=\"javascript:void(0);\">Loading</a></li></ul></li>";
			}
		}
		$(ulId).innerHTML = html;
		if(html == ""){
			$(ulId).parentNode.getElementsByTagName('IMG')[0].style.visibility = "hidden";
			$(ulId).style.display="none";
		}
		parseSubItems(ulId,parentId);
	});
}

/**
* @todo：获取组织节点信息
* @date：2008-12-19
* @author：wangchen
*/
function getDetail(id){
	if(id == "0"){
		alert("根节点不能选择！");
		return;
	}
	parent.deptid.value = id;
	parent.deptname.value = $(id).parentNode.getElementsByTagName("A")[0].innerHTML;
	sClosed();
}
